package qaConsultant;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;

import org.junit.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;




public class CNST_Negative1 {
	WebDriver qq;
	String qlink, hptext;
	String FName, LName, Email, Phone, Country;
	
	
		
	@Before
		
	public void setUp() throws Exception {
		qq = new FirefoxDriver();
	    qlink = "http://qaonair.com/";
	    qq.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
	  }

	
    @Test
    
    public void testNewConsultant() throws BiffException, IOException, RowsExceededException, WriteException {
    	
    	String qlink1 = qlink + "work-qa-onair/";
    	String xlFilePath="C:\\Users\\Sushma\\Desktop\\Selenium LIVE project - Jan 2014\\My Code\\DDF97WB2.xls";
 		String lname,email,phone,country, err_msg;
    	FileInputStream fi = new FileInputStream(xlFilePath);
    	Workbook w = Workbook.getWorkbook(fi);
    	Sheet s = w.getSheet(0);
       	 
    		
    		lname = s.getCell(1,1).getContents();
    		email = s.getCell(2,1).getContents();
    		phone= s.getCell(3,1).getContents();
    		country= s.getCell(4,1).getContents();
    		
    		
    		//input values to consultant fields
    		qq.navigate().to(qlink1);
    		
    		
    		qq.findElement(By.id("inf_field_LastName")).sendKeys(lname);
    	   	qq.findElement(By.id("inf_field_Email")).sendKeys(email);
    		qq.findElement(By.id("inf_field_Phone1")).sendKeys(phone);
    		new Select(qq.findElement(By.id("inf_field_Country"))).selectByValue(country);
    		
    		
    		qq.findElement(By.cssSelector("input[type = \"submit\"]")).click();
    		err_msg = qq.findElement(By.id("webformErrors")).getText();
    		System.out.println(err_msg);
    		
    		
    		
    		File op = new File("C:\\Users\\Sushma\\Desktop\\Selenium LIVE project - Jan 2014\\My Code\\op1.xls");
    		WritableWorkbook wb = Workbook.createWorkbook(op);
    		wb.createSheet("RES",0);
    		WritableSheet ws = wb.getSheet(0);
    		Label l = new Label(0,0,"RESULT");
    		ws.addCell(l);
    		Label l1 = new Label(0,1,"PASS");
    		ws.addCell(l1);    		
    		Label m = new Label(1,0,"Valdation Error");
    		ws.addCell(m);
    		Label m1 = new Label(1,1,err_msg);
    		ws.addCell(m1);
    		
    		wb.write();
    		wb.close();
    }		
	  
	  @After
	  public void tearDown() throws Exception {
	    qq.quit();
	  }  
}

